<template>
  <div class="table_box_hy hf hybm">
    <div class="hybm_box xszm">
      <div class="hybm_title">{{ this.$route.meta.title }}</div>
      <div class="xszm_dc" @click="exportinfo()">
        导出<i class="el-icon-upload2"></i>
      </div>
    </div>
    <div class="table_item_hy hybm_item">
      <el-table :data="tableData" stripe fit>
        <el-table-column width="135" type="index" label="序号">
        </el-table-column>
        <el-table-column prop="class_name" label="课程名称"> </el-table-column>
        <el-table-column prop="schedule" label="学习进度">
          <template slot-scope="scope">
            <!-- <span>{{ (scope.row.schedule).toFixed() * 100 + "%" }}</span> -->
            {{ (scope.row.schedule * 100 ).toFixed() + "%"  }}
          </template>
        </el-table-column>
        <el-table-column prop="posit" label="学时"> </el-table-column>
      </el-table>
    </div>
    <div class="pagination_hy">
      <el-pagination
        hide-on-single-page
        background
        :pager-count="5"
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :current-page="page"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
import { xlsx } from "../../utils/getXlsx.js";

export default {
  data() {
    return {
      tableData: [],
      total: 0,
      page: 1,
    };
  },
  mounted() {
    this.getinfo();
  },
  methods: {
    /**
     * 分页
     * @param {页码} page
     */
    handleCurrentChange(page) {
      // 当分页发生变化时的处理函数
      this.page = page;
      this.getinfo();
    },
    /**
     * 获取列表
     */
    getinfo() {
      let that = this;
      let data = {
        page: that.page,
      };
      that.$http.post("education/education_prove", data).then((res) => {
        if (res.code === 1) {
          that.total = res.data.total;
          that.tableData = res.data.data;
        } else {
          that.total = 0;
          that.tableData = [];
        }
      });
    },
    /**
     * 导出
     */
    exportinfo() {
      let that = this;
      let data = {};
      that.$http.post("education/education_prove_export", data).then((res) => {
        if (res.code == 1) {
          let fields = {
            title1: "课程名称",
            title2: "学习进度",
            title3: "学时",
          };
          let arry = [];
          res.data.forEach((item) => {
            arry.push({
              title1: item.class_name,
              title2: Number(item.schedule) * 100 + "%",
              title3: item.posit,
            });
          });
          xlsx(arry, fields, "学时证明");
        } else {
          let obj = {
            code: 2,
            msg: "暂无学时导出",
          };
          that.$self.ts(obj);
        }
      });
    },
    //==========
  },
};
</script>
  <style>
.hybm {
  border: 1px solid #ddd;
  background: #ffffff;
  border-radius: 0.125rem;
  box-shadow: 1px 1px 3px 2px rgba(0, 0, 0, 0.15);
  padding-bottom: 0.375rem;
}
.hybm_box {
  height: 0.7625rem;
  display: flex;
  align-items: center;
  border-bottom: 0.0125rem solid #1954a4;
  padding-left: 0.25rem;
  box-sizing: border-box;
}
.hybm_title {
  border-left: 0.05rem solid #1954a4;
  padding-left: 0.1375rem;
  box-sizing: border-box;
  font-size: 0.25rem;
  font-weight: 400;
  color: #1954a4;
}
.hybm_item {
  width: 14rem;
  margin: auto;
  padding-top: 0.1725rem;
}
.xszm {
  display: flex;
  justify-content: space-between;
  padding-right: 0.25rem;
}
.xszm_dc {
  font-size: 0.225rem;
  font-weight: 400;
  color: #1954a4;
  cursor: pointer;
}
.xszm_dc i {
  margin-left: 0.0375rem;
}
</style>